Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API: Themes: Expose some additional basic fields #222

Closed
wants to merge 38 commits into from
Closed

REST API: Themes: Expose some additional basic fields #222

wants to merge 38 commits into from

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Apr 14, 2020

The /wp/v2/themes endpoint currently only exposes each theme's theme_supports field, but nothing else -- not even theme name or title.

See https://core.trac.wordpress.org/ticket/49906.

Needed for WordPress/gutenberg#21578 -- you can use that PR to test this one 🙂 I'm adding all the fields that I think will be needed to implement WordPress/gutenberg#20469 (comment):

image

That is:

  • author
  • author_name
  • author_uri
  • description
  • name
  • screenshot
  • stylesheet
  • template
  • theme_uri
  • version

Implementation loosely inspired by https://github.com/Automattic/jetpack/blob/f6f313d268c336491c8bca1afcf3e5d3663597ce/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@ockham
Copy link
Contributor Author

ockham commented Apr 14, 2020

/cc @kadamwhite

@TimothyBJacobs
Copy link
Member

Looks great! Are you interested in adding tests for this?

@ockham
Copy link
Contributor Author

ockham commented Apr 14, 2020

Looks great! Are you interested in adding tests for this?

Thanks! Sure, I'll add some tomorrow 😄

@ockham
Copy link
Contributor Author

ockham commented Apr 15, 2020

Update, I've fixed the failing unit tests and lint.

I haven't yet added new tests, since I'm still struggling with setting up the tests environment on my Linux box. I asked on Core Slack: https://wordpress.slack.com/archives/C02RQBWTW/p1586985925240400

@ockham ockham changed the title REST API: Themes: Expose some additional basic field REST API: Themes: Expose some additional basic fields Apr 16, 2020
@ockham
Copy link
Contributor Author

ockham commented Apr 16, 2020

I managed to get unit tests to run locally, and added a few more fields and corresponding tests (see updated PR description). I'd say this is ready for review 🙂

ockham added a commit to WordPress/gutenberg that referenced this pull request Apr 17, 2020
Display the current theme name in the template selector of `edit-site`.

Since the `/themes` endpoint currently only exposes the `theme_supports` field for each theme, this PR adds a number of additional fields to it, using the `rest_prepare_theme` hook. (I also filed a WordPress/wordpress-develop#222 against Core to extend the, err, upstream endpoint accordingly so that we can eventually drop the filter.)

In addition, this PR adds a new `getCurrentTheme` selector and related reducer/resolver/action to `core-data` (including a `themes` reducer for better normalization).

Finally, that selector is used to render the theme name in `edit-site`'s template selector.

The fields I've chosen to add should be sufficient to implement the on-hover previews seen at #20469 (comment).

However, this PR doesn't implement those previews yet, since we need to implement the underlying fly-out menu component first (see #20470).
@ockham
Copy link
Contributor Author

ockham commented Apr 20, 2020

cc/ @mcsf for review. Because it's a themes endpoint! 🎉

@mcsf
Copy link

mcsf commented Apr 21, 2020

Because it's a themes endpoint! 🎉

Good times!

Looks great, as far as I'm concerned. I'd defer to Timothy or K Adam for the final green light, though.

@ockham
Copy link
Contributor Author

ockham commented Apr 22, 2020

Looks great, as far as I'm concerned. I'd defer to Timothy or K Adam for the final green light, though.

@kadamwhite @TimothyBJacobs Pretty pleaaase? 😊

Copy link
Member

@TimothyBJacobs TimothyBJacobs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @ockham! Left comments with a couple of minor changes to the formatting of the response.

ockham and others added 6 commits May 18, 2020 13:46
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
@TimothyBJacobs
Copy link
Member

Hey @ockham just checking in on this!

@ockham
Copy link
Contributor Author

ockham commented Jun 2, 2020

Hey @ockham just checking in on this!

Thanks! I'm back today from 2 weeks of maintenance rotation, picking this up again 👍

@TimothyBJacobs
Copy link
Member

@ockham To clarify, the type should still be string but have a format => uri.

@ockham
Copy link
Contributor Author

ockham commented Jun 4, 2020

@ockham To clarify, the type should still be string but have a format => uri.

Fixed by 7f5db79 🙂

@TimothyBJacobs
Copy link
Member

Merged in r47921.

@ockham ockham deleted the add/rest-api/themes/basic-fields branch June 8, 2020 11:54
ockham added a commit to WordPress/gutenberg that referenced this pull request Jun 28, 2020
In #21578, I added a few fields to Core's `/themes` endpoint, for use by the Site Editor's Template Switcher (see both #21578 and #21768). I then submitted those changes as a [PR](WordPress/wordpress-develop#222) against Core. That PR underwent a number of modifications and was eventually merged; the new fields will be part of the `/themes` endpoint exposed by Core starting from the next WP release.

This PR updates the fields added by Gutenberg to follow the same semantics, as well as the callsites that use that endpoint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants